package foo.brindille.web;

import java.util.HashMap;
import java.util.Map;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.mvel2.templates.TemplateCompiler;
import org.mvel2.templates.TemplateRuntime;

import com.google.inject.Inject;

import foo.brindille.template.TemplateProvider;

@Path("/")
public class Base {
    
    @Inject
    TemplateProvider templateProvider;
    
    @GET
    @Produces("text/plain")
    @Path("helloworld")
    public String getClichedMessage() {        
        
        return (String) TemplateRuntime.execute(TemplateCompiler.compileTemplate("Hello World"), new HashMap());
    }

    @GET
    @Produces(MediaType.TEXT_HTML)
    @Path("helloworld/{username: [a-zA-Z][a-zA-Z_0-9]*}")
    public String getMessage(@PathParam("username") String userName) {
       
        Map model = new HashMap();
        model.put("username", userName);
        
        
        return (String) TemplateRuntime.execute(TemplateCompiler.compileTemplate("Hello commence par a @{username}"), model);
    }
    
    @GET
    @Produces("text/html")
    @Path("helloworld/{username}")
    public String getClichedMfeessage(@PathParam("username") String userName) {
       
        Map model = new HashMap();
        model.put("username", userName);
        
        
        return (String) TemplateRuntime.execute(TemplateCompiler.compileTemplate("Hello plop  @{username}"), model);
    }
    

}
